package com.lkbaby.home.service.impl;

import com.lkbaby.home.dao.ContentDao;
import com.lkbaby.home.entity.Content;
import com.lkbaby.home.service.ContentService;
import com.lkbaby.home.util.MyIDUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * (Content)服务接口实现层
 *
 * @author makejava
 * @since 2022-09-21 09:41:55
 */
@Service
public class ContentServiceImpl implements ContentService {

	@Resource(type = ContentDao.class)
	private ContentDao contentDao;

	@Override
	public List<Content> queryList() {
		return contentDao.selectList(null);
	}

	@Override
	public boolean insert(Content content) {
		if (content == null) {
			return false;
		}
		content.setId(MyIDUtils.getNewID());
		return contentDao.insert(content) > 0;
	}

	@Override
	public boolean update(Content content) {
		if (content == null) {
			return false;
		}
		return contentDao.updateById(content) > 0;
	}

	@Override
	public boolean remove(Content content) {
		if (Objects.isNull(content) || !StringUtils.hasText(content.getId())) {
			return false;
		}
		return contentDao.deleteById(content) > 0;
	}
}

